Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow message body redaction #67

Merged
merged 4 commits into from
Feb 21, 2024
Merged

Conversation

mdlavin
Copy link
Member

@mdlavin mdlavin commented Feb 15, 2024

Some messages from the member ops bot will contain PHI. I'd like to redact that from the messages instead of logging it.

@mdlavin mdlavin requested a review from aecorredor February 15, 2024 18:31
@mdlavin mdlavin force-pushed the allow-message-body-redaction branch from 447fd43 to d509ed9 Compare February 15, 2024 18:32
@mdlavin
Copy link
Member Author

mdlavin commented Feb 15, 2024

Woah, only after creating this did I see - #61 (comment). I'd love to hear @aecorredor's thoughts about this

@mdlavin mdlavin requested a review from swain February 15, 2024 18:32
Copy link
Member

@aecorredor aecorredor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we now cover SQS. The negative side is that we now have two solutions for the same thing: one in the dynamo stream handler and one for the SQS one. It'd be great to be able to consolidate.

I think we could make SQS safe now and come back to consolidate later though.

src/sqs.ts Outdated
try {
return redactor(body);
} catch (error) {
logger.error({ error, body }, 'Failed to redact message body');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this did in fact include PHI and someone wanted to redact, but did something wrong, we'll still end up logging the PHI. Does it make sense to just not log the body here?

@aecorredor
Copy link
Member

I approved, but I realized that logging the body in the catch might actually be worth removing.

@mdlavin
Copy link
Member Author

mdlavin commented Feb 15, 2024

I approved, but I realized that logging the body in the catch might actually be worth removing.

I left a comment about that in the testcase. What do you think of my logic? @aecorredor

aecorredor
aecorredor previously approved these changes Feb 15, 2024
src/sqs.test.ts Outdated
Comment on lines 139 to 140
// unredacted error allows for easier debugging. Leaking a small amount of
// PHI to Sumo is better than having a system that cannot be debugged.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I did miss this. Sorry. If the tradeoff is legally acceptable, I'm all for it. Easier debugging is always better.

Copy link
Member Author

@mdlavin mdlavin Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legally I think we're fine. The biggest risk I can think of would be constantly failing redaction logic that logs lots of data and we don't notice. An alternative would be to completely fail and to log the unredacted body. That would force a fix while giving enough data to debug when needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swain @indigocarmen What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you have in mind for when you say "completely fail". Since this happens in an SQS handler, it retries based on the queue settings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean throw an exception without handling the message rather than keep going. Throwing the exception would mean that it would be hard to ignore the failure to redact. There would be a small amount of PHI logged for that one message. By logging a warning, it would be pretty easy to ignore and then have the logs full of PHI over many messages.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...I think if a developer has explicitly provided logic for redacting data from the message body, it seems like we should not definitely not log that data. Logging a small amount of PHI seems like it is theoretically not okay, right?

@mdlavin It seems like your goal in including that log is supporting debugging. Could we log the SQS message id for that particular record instead of the full body?

Copy link
Member Author

@mdlavin mdlavin Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging a small amount of PHI seems like it is theoretically not okay

I think it's fine as an edgecase. Sumo can hold PHI and we want to minimize it.

Could we log the SQS message id for that particular record instead of the full body?

How does a developer debug with that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we log the SQS message id for that particular record instead of the full body?

How does a developer debug with that?

Good question. Thinking deeper, I couldn't come up with a solid path.

I think it's fine as an edgecase. Sumo can hold PHI and we want to minimize it.

I think I disagree about having the behavior in this package, but I'm willing to commit. You're the first user of the feature, and it seems like you feel like it is important and will be useful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem like it should be possible to create a redacted log message that does contain PHI, but is still useful for debugging (e.g. contains ids, etc). But, approving to trust your judgement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a new fix. Here is how the code should work:

  1. If no redaction is enabled then the event body is logged as is
  2. If redaction is enabled and it does not error, then the redacted event body is logged
  3. If redaction is enabled and it fails, then the event is logged with the whole body repalced with 'REDACTED' and an RSA encrypted blob holding the body to be used for debugging. Devs could keep a private key to use for accessing the details when critical
  4. If redaction fail, and encryption fails, then the body is logged as 'REDACTED', the encryption failure is logged. No way to debug from this. Need to deliver a code fix to repair the failed encryption

It's the best mix of security + developer experience I could come up with. Sensitive data is unlikely to be leaked by accident and developers can get access to the failed event body by jumping through some manual steps of RSA decryption.

swain
swain previously approved these changes Feb 19, 2024
@mdlavin mdlavin dismissed stale reviews from swain and aecorredor via d0cd009 February 20, 2024 19:57
@mdlavin mdlavin merged commit e023961 into master Feb 21, 2024
4 checks passed
@mdlavin mdlavin deleted the allow-message-body-redaction branch February 21, 2024 18:31
Copy link

🎉 This PR is included in version 5.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants